﻿using Model;
using MongoDB.Driver;
using MongoService.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MongoService.Interface
{
    public interface IMongoRepository<T, TKey> : IQueryable<T> where T : IMongoEntity<TKey>
    {
        IMongoCollection<T> Collection { get; }
        /// <summary>
        /// 单条数据查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetById(TKey id);
        /// <summary>
        /// 集合查询
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        IEnumerable<T> GetByFilter(Expression<Func<T, bool>> filter);
        /// <summary>
        /// 单条数据添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        T Add(T entity);
        /// <summary>
        /// 多条数据添加
        /// </summary>
        /// <param name="entities"></param>
        void Add(IEnumerable<T> entities);
        /// <summary>
        /// 单条数据按条件更新全部字段
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(Expression<Func<T, bool>> filter, T entity);
        /// <summary>
        /// 单条数据按条件更新部分字段
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(Expression<Func<T, bool>> filter, UpdateDefinition<T> entity);
        /// <summary>
        /// 单条数据按主键ID更新全部字段
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(T entity);
        /// <summary>
        /// 多条数据按主键ID更新全部字段
        /// </summary>
        /// <param name="entities"></param>
        void Update(IEnumerable<T> entities);
        /// <summary>
        /// 按主键ID删除单条数据
        /// </summary>
        /// <param name="id"></param>
        void Delete(TKey id);
        /// <summary>
        /// 按条件删除多条数据
        /// </summary>
        /// <param name="filter"></param>
        void Delete(Expression<Func<T, bool>> filter);
    }
}
